<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>盘点库存</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#btnExport").click(function(){
				top.$.jBox.confirm("确认要导出库存盘点数据吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#searchForm").attr("action","${ctx}/ka/checkInventory/export");
						$("#searchForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").attr("action","${ctx}/ka/checkInventory/list");
			$("#searchForm").submit();
        	return false;
        }
		
		function clearForm(){
			$("#categoryId").val('');
			$("#productCode").val('');
			$("#supplierId").val('');
			$("#startDate").val('');
			$("#endDate").val('');
			$("#state").val('');
			$("#searchForm").attr("action","${ctx}/ka/checkInventory/list");
			$("#searchForm").submit();
		}
		
		var check_val = [];
		//全选
		function selectAll(n){
			
			if(n.checked){
				check_val = []
				$("input[type=checkbox]").each(function(i,n) {
					if(i>0){
						this.checked = true; 
				        check_val.push(n.value)
					}
		        });  
			}else{
				$("input[type=checkbox]").each(function(i,n) {  
		            this.checked = false; 
		            check_val = []
		        });
			}
		}
		//单选
		function check(n){
		
			if(n.checked){
				check_val.push(n.value)
			}else{
				check_val.splice($.inArray(n.value,check_val),1)
			}
		}
		
		//批量删除
		function deleteAll(){
			
			if(check_val==null||check_val ==''||check_val==undefined){
				alertx("请选中删除的货品信息");
				return false;
			}
			return confirmx('确认要删除该货品信息吗？',"${ctx}/ka/checkInventory/deleteAll?ids="+check_val);
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ka/checkInventory/">库存列表</a></li>
		<%-- <shiro:hasPermission name="ka:productManage:edit"><li><a href="${ctx}/ka/productManage/form">货品管理添加</a></li></shiro:hasPermission> --%>
	</ul>
	<form:form id="searchForm" modelAttribute="productManage" action="${ctx}/ka/checkInventory/list" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/>
		<ul class="ul-form">
			<li><label>品类：</label>
				<form:select path="categoryId" class="input-medium">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getCategory() }" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>供应商：</label>
				<form:select path="supplierId" class="input-medium" >
					<form:option value="" label="全部"/>
					<form:options items="${fns:getSupplier()}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>货号：</label>
				<form:input path="productCode" htmlEscape="false" maxlength="64" class="input-medium"/>
			</li>
			<li class="clearfix"></li>
		</ul>
		<ul class="ul-form">
			<li><label>状态：</label>
				<form:select path="state" class="input-medium">
					<form:option value="" label="全部"></form:option>
					<form:option value="0" label="已新增待质检"></form:option>
					<form:option value="1" label="已入库待上架"></form:option>
					<form:option value="2" label="已上架"></form:option>
					<form:option value="3" label="已售出待质检"></form:option>
					<form:option value="4" label="已下架"></form:option>
					<form:option value="5" label="质检不通过"></form:option>
					<form:option value="6" label="退货（非残次品）"></form:option>
					<form:option value="7" label="退货（残次品）"></form:option>
				</form:select>
			</li>
			<li><label>入库时间：</label>
				<input name="startDate" id="startDate" type="text"  maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${productManage.startDate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>至<input name="endDate" id="endDate" type="text"  maxlength="20" class="input-medium Wdate required"
					value="<fmt:formatDate value="${productManage.endDate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" onclick="return page();"/></li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="button" onclick="clearForm()" value="重置"/></li>
			<li class="btns"><input id="btnExport" class="btn btn-primary" type="button" value="导出"/></li>
			<li class="clearfix"></li>
		</ul>
		<shiro:hasPermission name="ka:checkInventory:delete">
			</br>
			<ul class="ul-form">
				<li class="btns"><label></label><input id="btnDelete" class="btn btn-primary" type="button" onclick="deleteAll()" value="批量删除"/></li>
				<li class="clearfix"></li>
			</ul>
		</shiro:hasPermission>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th><input type="checkbox" name="ck" onclick="selectAll(this)"></th>
				<th>品类</th>
				<th>货号</th>
				<th>供应商</th>
				<th>尺码</th>
				<th>颜色</th>
				<th>件数</th>
				<th>价格</th>
				<th>货架</th>
				<th>入库时间</th>
				<th>状态</th>
				<shiro:hasPermission name="ka:productManage:edit"><th>操作</th></shiro:hasPermission>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="productManage">
			<tr>
				<td>
					<input type="checkbox" value ="${productManage.id }" onclick="check(this)">
				</td>
				<td><a href="${ctx}/ka/checkInventory/form?id=${productManage.id}">
					${productManage.categoryName}
				</a></td>
				<td>
					${productManage.productCode}
				</td>
				<td>
					${productManage.supplierName}
				</td>
				<td>
					${productManage.sizeName}
				</td>
				<td>
					${productManage.colorName}
				</td>
				<td>
					${productManage.num}
				</td>
				<td>
					${productManage.price}
				</td>
				<td>
					${productManage.gridNo}
				</td>
				<td>
					<fmt:formatDate value="${productManage.instockDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td>
					<c:choose>
						<c:when test="${productManage.state==0}">已新增待质检</c:when>
						<c:when test="${productManage.state==1}">已入库待上架</c:when>
						<c:when test="${productManage.state==2}">已上架</c:when>
						<c:when test="${productManage.state==3}">已售出待质检</c:when>
						<c:when test="${productManage.state==4}">已下架</c:when>
						<c:when test="${productManage.state==5}">质检不通过</c:when>
						<c:when test="${productManage.state==6}">退货（非残次品）</c:when>
						<c:when test="${productManage.state==7}">退货（残次品）</c:when>
					</c:choose>
				</td>
				<td>
    				<shiro:hasPermission name="ka:checkInventory:edit"><a href="${ctx}/ka/checkInventory/form?id=${productManage.id}" onclick="return confirmx('确认要修改该货品吗？', this.href)">修改</a></shiro:hasPermission>
					<shiro:hasPermission name="ka:checkInventory:delete"><a href="${ctx}/ka/checkInventory/delete?id=${productManage.id}" onclick="return confirmx('确认要删除该货品吗？', this.href)">删除</a></shiro:hasPermission>
					<shiro:hasPermission name="ka:checkInventory:edit">
					<c:choose>
						<c:when test="${productManage.state==5}"><a href="${ctx}/ka/checkInventory/checkInventoryForm?id=${productManage.id}" onclick="return confirmx('确认要入库质检吗？', this.href)">入库质检</a></c:when>
					</c:choose>
					</shiro:hasPermission>
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<table align="right" border="0">
		<tr>
			<td>合计：</td>
			<td>总件数:${statistics.total }(件)&nbsp;&nbsp;</td>
			<td>总入库价格：${statistics.instockPriceTotal }(元)</td>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td>平均入库价格:${statistics.instockPriceAvg }(元)</td>
		</tr>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>